Skip to content

feat(api): send X-Spoo-Client header on backend requests - #3

Merged
Zingzy merged 2 commits into
mainfrom
feat/client-header
Jul 22, 2026
Merged

feat(api): send X-Spoo-Client header on backend requests#3
Zingzy merged 2 commits into
mainfrom
feat/client-header

Conversation

@Zingzy

@Zingzy Zingzy commented Jul 22, 2026

Copy link
Copy Markdown
Member

Every request the CLI makes to the spoo.me API now carries an X-Spoo-Client: cli/<version> header so the backend can attribute traffic by client.

The version comes from the same goreleaser ldflags that already set main.version, with a bare cli fallback when the value does not match [A-Za-z0-9._-]{1,16} (for example snapshot builds). The header is set centrally in the API client's send plus the one out-of-band HEAD in Inspect, which never follows redirects, so it is only ever sent to the configured API base.

Summary by CodeRabbit

  • New Features

    • Added client identification to API requests through the X-Spoo-Client header.
    • Release builds now report their version when communicating with the API.
    • Development builds identify themselves as cli/dev.
  • Bug Fixes

    • Invalid or unsupported version values now fall back to a safe client identifier.

Every request to the spoo.me API now carries X-Spoo-Client: cli/<version>
so the backend can attribute traffic by client. The version is injected by
goreleaser and falls back to a bare cli value when it does not fit the
allowed charset. Only backend hosts receive the header.
Copilot AI review requested due to automatic review settings July 22, 2026 13:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Zingzy, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e5387c9e-418f-4ba3-8a42-c6ae8a996cee

📥 Commits

Reviewing files that changed from the base of the PR and between 174aa65 and 9584752.

📒 Files selected for processing (2)
  • internal/api/client.go
  • internal/api/client_test.go
📝 Walkthrough

Walkthrough

The CLI release build now injects its version into the API package. API requests and inspect requests send a validated X-Spoo-Client header, with tests covering default and malformed versions.

Changes

API attribution

Layer / File(s) Summary
Version metadata and header formatting
.goreleaser.yaml, internal/api/client.go
Release builds inject internal/api.Version; the client formats valid versions as cli/<version> and falls back to cli.
Request header propagation and validation
internal/api/client.go, internal/api/inspect.go, internal/api/client_test.go
Standard requests and inspect requests send X-Spoo-Client, with tests covering cli/dev and malformed versions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GoReleaser
  participant CLI
  participant API
  GoReleaser->>CLI: Inject release version
  CLI->>API: Send X-Spoo-Client header
  API-->>CLI: Return HTTP response
Loading

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the X-Spoo-Client header to API/backend requests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/client-header

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/api/inspect.go (1)

31-31: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for Inspect.

Inspect bypasses Client.send, so the existing TestDoSendsClientHeader does not exercise this new HEAD-request path. Add an httptest case asserting X-Spoo-Client == cli/dev and confirming redirects are not followed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/api/inspect.go` at line 31, Add regression coverage for the Inspect
HEAD-request path, which bypasses Client.send. Extend or add an httptest case
around Inspect that asserts the X-Spoo-Client header equals cli/dev and verifies
the HTTP client does not follow redirects.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/api/client.go`:
- Line 114: Update the HTTP client redirect policy around the request setup that
sets X-Spoo-Client so redirects remove this header before forwarding, or reject
cross-origin redirects. Add a regression test verifying the header is not sent
to redirected targets, especially across origins.

---

Nitpick comments:
In `@internal/api/inspect.go`:
- Line 31: Add regression coverage for the Inspect HEAD-request path, which
bypasses Client.send. Extend or add an httptest case around Inspect that asserts
the X-Spoo-Client header equals cli/dev and verifies the HTTP client does not
follow redirects.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 767112d4-86c1-4a22-9404-c6506fc02be7

📥 Commits

Reviewing files that changed from the base of the PR and between 697203b and 174aa65.

📒 Files selected for processing (4)
  • .goreleaser.yaml
  • internal/api/client.go
  • internal/api/client_test.go
  • internal/api/inspect.go

Comment thread internal/api/client.go

@Zingzy Zingzy left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mergeable, nothing blocking.

  • The ldflags -X target matches go.mod's module path exactly (checked), so release builds get cli/<version> and dev builds fall back to cli/dev.
  • The malformed-version fallback to bare cli is a nice detail: the backend drops the whole tag when the value does not match its shape, so degrading to slug-only preserves attribution where a raw cli/0.2.0-SNAPSHOT-... would lose it entirely. The test table covers exactly that case.
  • Inspect's hand-built no-follow request is the one call outside send(), and it is tagged.
  • go test passes locally and CI is green.

The default Go client forwards custom headers to redirect targets on
other hosts. Attribution belongs to the spoo API only, so CheckRedirect
drops X-Spoo-Client when a redirect leaves the original host. Same-host
redirects keep it. Regression tests cover both.
@Zingzy

Zingzy commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

The CheckRedirect addition at 9584752 verified: comparing against via[0] is the right anchor because Go re-copies custom headers from the initial request on every hop, so a same-host hop after a cross-host detour correctly regains the header and every hop of a cross-host chain correctly drops it. The two new tests pin exactly those directions, and Inspect's no-follow client is unaffected. go test passes locally. Still mergeable, nothing further.

@Zingzy
Zingzy merged commit 45fab58 into main Jul 22, 2026
2 checks passed
@Zingzy
Zingzy deleted the feat/client-header branch August 16, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants